<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="业务单外协完成" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doShow(id){
		showWin(900,600,"/business/BusinessBillPrint.ihtm?type=SIMPLE&id="+id);
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		window.location="/cooper/BbItemListForCooperComp.ihtm?"+str+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		if(ob_arr.length>=it.getAttribute("index")){
			str=ob_arr[it.getAttribute("index")-1].getAttribute("billId");
		}
		if(str==""){
			return;
		}
		doShow(str);
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function createPageParaStr(){
		var str="est_name="+encodeURIComponent(document.getElementById("est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("bill_code").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("mt_name").value);
		str=str+"&mt_id="+document.getElementById("mt_id").value;
		str=str+"&content="+encodeURIComponent(document.getElementById("content").value);
		return str;
	}
	
	function createProgramParaStr(){
		var str="est_name="+encodeURIComponent(document.getElementById("hid_est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("hid_bill_code").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("hid_mt_name").value);
		str=str+"&mt_id=${mtId}";
		str=str+"&content="+encodeURIComponent(document.getElementById("hid_content").value);
		return str;
	}
	function doSearch(){
		var str="";
		if(IsAdvSearch){//高级
			str="search_type=1";
			if(document.getElementById("cb_est").checked){
				var estName=document.getElementById("est_name").value.trim();
				if(estName==null || estName==""){
					ShowAlert('提示框','请输入订货单位',200,100);
					return;
				}
				str=str+"&cb_est=1";
			}
			if(document.getElementById("cb_bill_code").checked){
				var billCode=document.getElementById("bill_code").value.trim();
				if(billCode==null || billCode==""){
					ShowAlert('提示框','请输入业务单号',200,100);
					return;
				}
				str=str+"&cb_bill_code=1";
			}
			if(document.getElementById("cb_mt").checked){
				var mtId=document.getElementById("mt_id").value;
				if(mtId==null || mtId=="" || mtId=="0"){
					ShowAlert('提示框','请选择项目类型',200,100);
					return;
				}
				str=str+"&cb_mt=1";
			}
			if(document.getElementById("cb_content").checked){
				var content=document.getElementById("content").value.trim();
				if(content==null || content==""){
					ShowAlert('提示框','请输入摘要',200,100);
					return;
				}
				str=str+"&cb_content=1";
			}
		}else{//快速
			str="search_type=2";
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/cooper/BbItemListForCooperComp.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbEst=='1'}">str=str+"&cb_est=1";</c:if>
			<c:if test="${cbBillCode=='1'}">str=str+"&cb_bill_code=1";</c:if>
			<c:if test="${cbMt=='1'}">str=str+"&cb_mt=1";</c:if>
			<c:if test="${cbContent=='1'}">str=str+"&cb_content=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function selectMakeType(){
		var url="/base/MakeTypeListForSelect.ihtm";
		ShowIframe("选择项目类型",url,310,500,"selectMakeTypeCallBack()");
	}
	function selectMakeTypeCallBack(){
		if(popRetVal!=null){
			document.getElementById("mt_id").value=popRetVal[0];
			document.getElementById("mt_name").value=popRetVal[1];
			doAutoCheck("cb_mt");
		}
	}
	function doComplete(id){
		ShowConfirm('确认框','确定完成吗？',340,80,"doCompleteCallBack("+id+")");
	}
	function doCompleteCallBack(id){
		if(popRetVal!=null){
			var url="/cooper/BbItemCooperComp.ihtm?id_str="+id;
			ShowIframe("业务单外协完工",url,200,200,"refreshWin()");
		}
	}
	function refreshWin(){
		if(popRetVal!=null){
			window.location.reload(true);
		}
	}
	function doMutiComplete(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].value;
			}
		}
		if(str!=""){
			doComplete(str);
		}else{
			ShowAlert('提示框','请选择要完成的业务单项目',200,100);
		}
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>业务单外协完成</h1>
	            <span class="Note">标记为外协完成的业务单才不会出现在外协开单的选择界面上</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_mt" id="cb_mt" <c:if test="${cbMt=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			项目类型
	            		</th>
	            		<td class="c1" width="260px">
	            			<input type="text" class="TextBox readonly" readonly="true" name="mt_name" id="mt_name" value="<c:out value="${mtName}" />" >
							<img class="imgIconButton" src="/images/make-a.gif" onClick="selectMakeType();" />
							<input type="hidden" id="hid_mt_name" value="<c:out value="${mtName}" />">
							<input type="hidden" name="mt_id" id="mt_id" value="${mtId}">
	            		</td>
	            	</table>
	            </span>
				<span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
		  			<input type="button" value=" 完 成" onClick="doMutiComplete();" id="sCompButton" name="sCompButton" class="buttom search-audit">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_est" id="cb_est" <c:if test="${cbEst=='1'}">checked="true"</c:if>>
			        			订货单位
			        		</th>
			    			<td class="c1" width="240px">
			        			<input type="text" class="TextBox" name="est_name" id="est_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_est');" value="<c:out value="${estName}" />" >
								<input type="hidden" id="hid_est_name" value="<c:out value="${estName}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_bill_code" id="cb_bill_code" <c:if test="${cbBillCode=='1'}">checked="true"</c:if>>
			        			业务单号
			        		</th>
			    			<td class="c1">
			        			<input type="text" class="TextBox" name="bill_code" id="bill_code" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_bill_code');" value="<c:out value="${billCode}" />" >
								<input type="hidden" id="hid_bill_code" value="<c:out value="${billCode}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_content" id="cb_content" <c:if test="${cbContent=='1'}">checked="true"</c:if>>
			        			摘要
			        		</th>
			    			<td class="c1">
			        			<input type="text" class="TextBox" maxlength="50" name="content" id="content" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_content');" value="${content}" >
								<input type="hidden" id="hid_content" value="<c:out value="${content}" />">
			    			</td>
			    		</tr>
			    	</table>
					
					<div class="OptionOrderBy">
						<span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>

		    <div class="table-list">
		        <table width="100%">
					<tr>
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="12%">单号</th>
						<th width="8%" >订货日期</th>
						<th width="12%" >订货单位</th>
						<th width="11%" >摘要</th>
						<th width="8%" >项目类型</th>
						<th width="11%" >内容</th>
						<th width="11%" >材质</th>
						<th width="12%" >规格</th>
						<th width="5%" >单位</th>
						<th width="6%" >数量</th>
						<th width="4%" >操作</th>
					</tr>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td ><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' value="${item[1].businessBillItem.id}" billId="${item[0].id}"></td>
						<td><a href="javascript:doShow(${item[0].id});">${item[0].billCode}</a></td>
						<td><fmt:formatDate value="${item[0].orderDate}" pattern="yyyy-MM-dd"/></td>
						<td>${item[2].estName}<c:if test="${item[2].linkman!=null && item[2].linkman!=''}">(${item[2].linkman})</c:if></td>
						<td>${item[0].content}</td>
						<td>${item[1].makeTypeName}</td>
						<td>${item[1].businessBillItem.finishedContent}</td>
						<td>${item[1].businessBillItem.proName}</td>
						<td>${item[1].businessBillItem.specification}</td>
						<td>
							<c:if test="${item[1].businessBillItem.priceType=='AREA'}">平方米</c:if>
							<c:if test="${item[1].businessBillItem.priceType=='LENGTH'}">
								<c:if test="${item[1].businessBillItem.lengType=='M'}">米</c:if><c:if test="${item[1].businessBillItem.lengType=='CM'}">公分</c:if>
							</c:if>
							<c:if test="${item[1].businessBillItem.priceType=='AMOUNT'}">${item[1].businessBillItem.unit}</c:if>
						</td>
						<td>
							<c:if test="${item[1].businessBillItem.priceType=='AREA' || item[1].businessBillItem.priceType=='LENGTH'}"><commonTag:parseBigDecimal source="${item[1].businessBillItem.squareNum}" /></c:if>
							<c:if test="${item[1].businessBillItem.priceType=='AMOUNT'}"><commonTag:parseBigDecimal source="${item[1].businessBillItem.amount}" /></c:if>
						</td>
						<td>
							<a href="javascript:doComplete('${item[1].businessBillItem.id}');">完成</a>
						</td>
					</tr>
					</c:forEach>
				</table>
			</div>

			<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_mt').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_mt').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
